// Created: Dec 14, 2014 
//
// Author: wjinwen.1988@gmail.com

#ifndef CHI_NET_EVENT_LOOP_THREAD_H
#define CHI_NET_EVENT_LOOP_THREAD_H

#include <functional>

#include "chi/thread.h"
#include "chi/mutex.h"
#include "chi/condition.h"

namespace chi {
namespace net {

class EventLoop;

class EventLoopThread {
 public:
  using ThreadInitCallback = std::function<void (EventLoop*)>;

  EventLoopThread(const ThreadInitCallback& cb = ThreadInitCallback());
  ~EventLoopThread();

  EventLoopThread(const EventLoopThread&) = delete;
  void operator= (const EventLoopThread&) = delete;

  EventLoop* StartLoop();
  void StopLoop();
 private:
  void ThreadRuntime();

  EventLoop* loop_;
  bool exiting_;
  Thread thread_;
  MutexLock mutex_;
  Condition cond_;
  ThreadInitCallback callback_;
};
} 
}

#endif  
